var btree = {
    value:"A",
    leftLeaf:{
        value:"B",
        leftLeaf:{
            value:"D",
            leftLeaf:null,
            rightLeaf:null
        },
        rightLeaf:{
            value:"E",
            leftLeaf:null,
            rightLeaf:null
        }
    },
    rightLeaf:{
        value:"C",
        leftLeaf:{
            value:"F",
            leftLeaf:null,
            rightLeaf:null
        },
        rightLeaf:{
            value:"G",
            leftLeaf:null,
            rightLeaf:null
        }
    }
}
//先序遍历 递归
function preorder1(root){
    if(!root) return
    console.log(root.value);
    preorder1(root.leftLeaf)
    preorder1(root.rightLeaf)
}
preorder1(btree)
//非递归
function preorder2(root){
    if(!root) return
    let stack=[root]
    while(stack.length>0){
        let node=stack.pop()
        console.log(node.value);
        if(node.rightLeaf){
            stack.push(node.rightLeaf)
        }
        if(node.leftLeaf){
            stack.push(node.leftLeaf)
        }
    }
}
